package com.evenmo.hrms.mapper.oldmapper.dynaSqlProvider;

import com.evenmo.hrms.pojo.Document;
import org.apache.ibatis.jdbc.SQL;

public class DocumentDynaSqlProvider {
    public String selectByParams(Document document) {
        return new SQL() {

            {

                SELECT("*");
                FROM("document");
                if (document.getFileName() != null) {
                    WHERE("fileName=#{fileName}");
                }
                if (document.getTitle() != null) {
                    WHERE("title like concat('%',#{title},'%')");
                }
                if (document.getUserId() != null) {
                    WHERE("userId=#{userId}");
                }
                if (document.getCreateTime() != null) {
                    WHERE("createTime=#{createTime}");
                }
                if (document.getRemark() != null) {
                    WHERE("remark like concat('%',#{remark},'%')");
                }

            }
        }.toString();
    }

    public String insertByParams(Document document) {
        return new SQL() {
            {

                INSERT_INTO("document");
                if (document.getTitle() != null) {
                    VALUES("title", "#{title}");
                }
                if (document.getUserId() != null) {
                    VALUES("userId", "#{userId}");
                }
                if (document.getFileName() != null) {
                    VALUES("fileName", "#{fileName}");
                }
                if (document.getRemark() != null) {
                    VALUES("remark", "#{remark}");
                }
                if (document.getCreateTime() != null) {
                    VALUES("createTime", "#{createTime}");
                }


            }
        }.toString();
    }


  public String  updateByParams(Document document){
        return new SQL(){
            {

                UPDATE("document");
                if (document.getCreateTime()!=null){
                    SET("createTime=#{createTime}");
                }
                if (document.getRemark()!=null){
                    SET("remark=#{remark}");
                }
                if (document.getFileName()!=null){
                    SET("fileName=#{fileName}");
                }
                if (document.getUserId()!=null){
                    SET("userId=#{userId}");
                }
                if (document.getTitle()!=null){
                    SET("title=#{title}");
                }
                WHERE("id=#{id}");

            }
        }.toString();
    }
}
